﻿package baidu.ui.controls
{
    import baidu.ui.core.*;
    import flash.display.*;
    import flash.text.*;

    public class Tooltip extends BUI
    {
        protected var textField:TextField;
        protected var background:Sprite;
        public static var defaultStyles:Object = {skin:"Tooltip_Skin", padding:2};

        public function Tooltip()
        {
            return;
        }// end function

        override public function get classStyles() : Object
        {
            return BUI.mergeStyles(super.classStyles, defaultStyles);
        }// end function

        public function get text() : String
        {
            return this.textField.text;
        }// end function

        public function set text(param1:String) : void
        {
            this.textField.text = param1;
            invalidate(Invalidation.SIZE);
            invalidate(Invalidation.STYLES);
            return;
        }// end function

        override protected function initUI() : void
        {
            super.initUI();
            this.textField = new TextField();
            addChild(this.textField);
            this.textField.autoSize = "left";
            return;
        }// end function

        override protected function draw() : void
        {
            if (isInvalid(Invalidation.STYLES, Invalidation.STATE))
            {
                this.drawBackground();
                invalidate(Invalidation.SIZE, false);
            }
            if (isInvalid(Invalidation.SIZE))
            {
                this.drawLayout();
            }
            super.draw();
            return;
        }// end function

        protected function drawLayout() : void
        {
            var _loc_1:* = getStyleValue("padding");
            var _loc_2:* = this.textField.width + _loc_1 * 2;
            this.background.width = this.textField.width + _loc_1 * 2;
            _width = _loc_2;
            var _loc_2:* = this.textField.height + _loc_1 * 2;
            this.background.height = this.textField.height + _loc_1 * 2;
            _height = _loc_2;
            var _loc_2:* = _loc_1;
            this.textField.y = _loc_1;
            this.textField.x = _loc_2;
            return;
        }// end function

        protected function drawBackground() : void
        {
            var _loc_1:* = this.background as MovieClip;
            this.background = getSkinInstance(getStyleValue("skin")) as Sprite;
            addChildAt(this.background, 0);
            if (_loc_1 != null && _loc_1 != this.background && contains(_loc_1))
            {
                removeChild(_loc_1);
            }
            return;
        }// end function

    }
}
